# -*- coding: utf-8 -*-

import os
import re

def read(filename):
    with open(filename, encoding='utf-8') as file_obj:
        contents = file_obj.read()
        return (contents.rstrip())
        
def write(filename,content):
    with open(filename, 'w', encoding='utf-8') as file_obj:
        file_obj.write(content)

readstr = read('data/original/log.txt')

optimizeStr = ""
bugfixStr = ""
businessStr = ""

for line in readstr.split("\n"):
    if (re.match(r"(.*)优化(.*)", line, flags=0)):
        optimizeStr += line
        optimizeStr += "\n"
        
    elif (re.match(r"(.*)适配(.*)", line, flags=0)):
        optimizeStr += line
        optimizeStr += "\n"
        
    elif (re.match(r"(.*)bugfix(.*)", line, flags=0)):
        bugfixStr += line
        bugfixStr += "\n"
        
    elif (re.match(r"(.*)bugly(.*)", line, flags=0)):
        bugfixStr += line
        bugfixStr += "\n"
    
    elif (re.match(r"(.*)bug(.*)", line, flags=0)):
        bugfixStr += line
        bugfixStr += "\n"
        
    elif (re.match(r"(.*)fix(.*)", line, flags=0)):
        bugfixStr += line
        bugfixStr += "\n"
    else:
        businessStr += line
        businessStr += "\n"


write(filename="data/bugfix.txt", content = bugfixStr)
write(filename="data/business.txt", content = businessStr)
write(filename="data/optimize.txt", content = optimizeStr)
